"""
If there is an exception, process the exception and write
exception information into log
Format of log:
    time,level of exception
    exception information:exception class, file name and line number
"""
import traceback
import logging


# try:
#     int("aa")
# except:
#     # get exception information throughout traceback module
#     errorMeg = traceback.format_exc()
#     print(errorMeg)
#
# print("abcdef")
# custom exception logging class
class customException():
    def __init__(self):
        logging.basicConfig(
            # directory of logging file
            filename="./error.log",
            # format output of logging
            format="%(asctime)s %(levelname)s \n %(message)s",
            datefmt="%Y-%m-%d %H:%M:%S"
        )
        # write logging information
        logging.error(traceback.format_exc())
# use custom exception processing class
try:
    int("aaa")
except:
    # use custom exception processing class in code block that processing exception
    customException()